package common

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/constants"
	commonPb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/common"
)

type optionRepository struct {
}

func NewOptionRepository() OptionRepositoryIface {
	return &optionRepository{}
}

func (r *optionRepository) RadarOpptyTypeOption(ctx context.Context, request *commonPb.GetRadarOpptyTypeOptionRequest) (*commonPb.GetRadarOpptyTypeOptionResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := commonPb.NewOptionServiceClient(conn)
	return client.GetRadarOpptyTypeOption(ctx, request)
}

func (r *optionRepository) RadarAreaOption(ctx context.Context, request *commonPb.GetRadarAreaOptionRequest) (*commonPb.GetRadarAreaOptionResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := commonPb.NewOptionServiceClient(conn)
	return client.GetRadarAreaOption(ctx, request)
}

func (r *optionRepository) GetOption(ctx context.Context, request *commonPb.GetOptionRequest) (*commonPb.GetOptionResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := commonPb.NewOptionServiceClient(conn)
	return client.GetOption(ctx, request)
}

func (r *optionRepository) GetInvestCompanyOption(ctx context.Context, request *commonPb.GetInvestCompanyOptionRequest) (*commonPb.GetInvestCompanyOptionResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := commonPb.NewOptionServiceClient(conn)
	return client.GetInvestCompanyOption(ctx, request)
}
